home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbteblt8.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  10.4 KB  |  423 lines

  1. /*
  2.  * TEGblt - ImageText expanded glyph fonts only.  For
  3.  * 8 bit displays, in Copy mode with no clipping.
  4.  */
  5.  
  6. /*
  7. Copyright 1989 by the Massachusetts Institute of Technology
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the name of M.I.T. not be used in
  14. advertising or publicity pertaining to distribution of the software
  15. without specific, written prior permission.  M.I.T. makes no
  16. representations about the suitability of this software for any
  17. purpose.  It is provided "as is" without express or implied warranty.
  18. */
  19.  
  20. /* $XConsortium: cfbteblt8.c,v 5.9 89/11/21 15:31:14 keith Exp $ */
  21.  
  22. #include    "X.h"
  23. #include    "Xmd.h"
  24. #include    "Xproto.h"
  25. #include    "fontstruct.h"
  26. #include    "dixfontstr.h"
  27. #include    "gcstruct.h"
  28. #include    "windowstr.h"
  29. #include    "scrnintstr.h"
  30. #include    "pixmapstr.h"
  31. #include    "regionstr.h"
  32. #include    "cfb.h"
  33. #include    "cfbmskbits.h"
  34. #include    "cfb8bit.h"
  35.  
  36. #if (PPW == 4)
  37.  
  38. #define glyphbits(bits,width,mask,dst)    getleftbits(bits,width,dst); \
  39.                     dst &= mask;
  40.  
  41. /*
  42.  * On little-endian machines (or where fonts are padded to 32-bit
  43.  * boundaries) we can use some magic to avoid the expense of getleftbits
  44.  */
  45.  
  46. #if (BITMAP_BIT_ORDER == LSBFirst || GLYPHPADBYTES == 4)
  47.  
  48. #if GLYPHPADBYTES == 1
  49. typedef unsigned char    *glyphPointer;
  50. #define USE_LEFTBITS
  51. #endif
  52.  
  53. #if GLYPHPADBYTES == 2
  54. typedef unsigned short    *glyphPointer;
  55. #define USE_LEFTBITS
  56. #endif
  57.  
  58. #if GLYPHPADBYTES == 4
  59. typedef unsigned int    *glyphPointer;
  60. #endif
  61.  
  62. #define GetBits4S   c = BitRight (*char1++, xoff1) | \
  63.             BitRight (*char2++, xoff2) | \
  64.             BitRight (*char3++, xoff3) | \
  65.             BitRight (*char4++, xoff4);
  66. #define GetBits4L   c = BitLeft  (*leftChar++, lshift) | \
  67.             BitRight (*char1++, xoff1) | \
  68.             BitRight (*char2++, xoff2) | \
  69.             BitRight (*char3++, xoff3) | \
  70.             BitRight (*char4++, xoff4);
  71. #define GetBits4U   c = *char1++ | \
  72.             BitRight (*char2++, xoff2) | \
  73.             BitRight (*char3++, xoff3) | \
  74.             BitRight (*char4++, xoff4);
  75.  
  76. #else
  77. typedef unsigned char    *glyphPointer;
  78. #define USE_LEFTBITS
  79.  
  80. #define GetBits4S   glyphbits (char1, widthGlyph, glyphMask, tmpSrc); \
  81.             c  = BitRight (tmpSrc, xoff1); \
  82.             char1 += glyphBytes; \
  83.             glyphbits (char2, widthGlyph, glyphMask, tmpSrc); \
  84.             c |= BitRight (tmpSrc, xoff2); \
  85.             char2 += glyphBytes; \
  86.             glyphbits (char3, widthGlyph, glyphMask, tmpSrc); \
  87.             c |= BitRight (tmpSrc, xoff3); \
  88.             char3 += glyphBytes; \
  89.             glyphbits (char4, widthGlyph, glyphMask, tmpSrc); \
  90.             c |= BitRight (tmpSrc, xoff4); \
  91.             char4 += glyphBytes; 
  92. #define GetBits4L   GetBits4S \
  93.             glyphbits (leftChar, widthGlyph, glyphMask, tmpSrc); \
  94.             c |= BitLeft (tmpSrc, lshift); \
  95.             leftChar += glyphBytes; 
  96.  
  97. #define GetBits4U   GetBits4S
  98.  
  99. #endif
  100.  
  101. #ifdef USE_LEFTBITS
  102. extern long endtab[];
  103.  
  104. #define IncChar(c)  (c = (glyphPointer) (((char *) c) + glyphBytes))
  105. #define GetBits1S   glyphbits (char1, widthGlyph, glyphMask, c); \
  106.             c = BitRight (c, xoff1); \
  107.             IncChar(char1);
  108. #define GetBits1L   GetBits1S \
  109.             glyphbits (leftChar, widthGlyph, glyphMask, tmpSrc); \
  110.             IncChar(leftChar); \
  111.             c |= BitLeft (tmpSrc, lshift);
  112. #define GetBits1U   glyphbits (char1, widthGlyph, glyphMask, c); \
  113.             IncChar(char1);
  114. #define GetBitsL    glyphbits (leftChar, widthGlyph, glyphMask, c); \
  115.             c = BitLeft (c, lshift); \
  116.             IncChar(leftChar);
  117. #else
  118. #define GetBits1S   c = BitRight (*char1++, xoff1);
  119. #define GetBits1L   c = BitLeft (*leftChar++, lshift) | \
  120.             BitRight (*char1++, xoff1);
  121. #define GetBits1U   c = *char1++;
  122. #define GetBitsL    c = BitLeft (*leftChar++, lshift);
  123. #endif
  124.  
  125. /* another ugly giant macro */
  126. #define SwitchEm    switch (ew) \
  127.             { \
  128.             case 0: \
  129.                 break; \
  130.             case 1: \
  131.                 while (hTmp--) { \
  132.                 GetBits \
  133.                 StoreBits0 \
  134.                 Loop \
  135.                 } \
  136.                 break; \
  137.             case 2: \
  138.                 while (hTmp--) { \
  139.                 GetBits \
  140.                 StoreBits0 FirstStep StoreBits(1) \
  141.                 Loop \
  142.                 } \
  143.                 break; \
  144.             case 3: \
  145.                 while (hTmp--) { \
  146.                 GetBits \
  147.                 StoreBits0 FirstStep StoreBits(1) Step StoreBits(2) \
  148.                 Loop \
  149.                 } \
  150.                 break; \
  151.             case 4: \
  152.                 while (hTmp--) { \
  153.                 GetBits \
  154.                 StoreBits0 FirstStep StoreBits(1) Step \
  155.                  StoreBits(2) Step StoreBits(3) \
  156.                 Loop \
  157.                 } \
  158.                 break; \
  159.             case 5: \
  160.                 while (hTmp--) { \
  161.                 GetBits \
  162.                 StoreBits0 FirstStep StoreBits(1) Step \
  163.                  StoreBits(2) Step StoreBits(3) Step \
  164.                 StoreBits(4) \
  165.                 Loop \
  166.                 } \
  167.                 break; \
  168.             case 6: \
  169.                 while (hTmp--) { \
  170.                 GetBits \
  171.                 StoreBits0 FirstStep StoreBits(1) Step \
  172.                  StoreBits(2) Step StoreBits(3) Step \
  173.                 StoreBits(4) Step StoreBits(5) \
  174.                 Loop \
  175.                 } \
  176.                 break; \
  177.             case 7: \
  178.                 while (hTmp--) { \
  179.                 GetBits \
  180.                 StoreBits0 FirstStep StoreBits(1) Step \
  181.                  StoreBits(2) Step StoreBits(3) Step \
  182.                 StoreBits(4) Step StoreBits(5) Step \
  183.                 StoreBits(6) \
  184.                 Loop \
  185.                 } \
  186.                 break; \
  187.             case 8: \
  188.                 while (hTmp--) { \
  189.                 GetBits \
  190.                 StoreBits0 FirstStep StoreBits(1) Step \
  191.                  StoreBits(2) Step StoreBits(3) Step \
  192.                 StoreBits(4) Step StoreBits(5) Step \
  193.                 StoreBits(6) Step StoreBits(7) \
  194.                 Loop \
  195.                 } \
  196.                 break; \
  197.             }
  198.  
  199. extern void miImageGlyphBlt();
  200.  
  201. void
  202. cfbTEGlyphBlt8 (pDrawable, pGC, xInit, yInit, nglyph, ppci, pglyphBase)
  203.     DrawablePtr pDrawable;
  204.     GC         *pGC;
  205.     int     xInit, yInit;
  206.     unsigned int nglyph;
  207.     CharInfoPtr *ppci;        /* array of character info */
  208.     unsigned char *pglyphBase;    /* start of array of glyphs */
  209. {
  210.     register unsigned long  c;
  211.     register unsigned long  *dst;
  212.     register unsigned long  leftMask, rightMask;
  213.     register int        hTmp;
  214.     register int        xoff1, xoff2, xoff3, xoff4;
  215.     register glyphPointer   char1, char2, char3, char4;
  216.  
  217.     CharInfoPtr        pci;
  218.     FontInfoPtr        pfi = pGC->font->pFI;
  219.     unsigned long    *dstLine;
  220.     glyphPointer    oldRightChar;
  221.     unsigned long    *pdstBase;
  222.     glyphPointer    leftChar;
  223.     int            widthDst;
  224.     int            widthGlyph;
  225.     int            h;
  226.     int            ew;
  227.     int            x, y;
  228.     BoxRec        bbox;        /* for clipping */
  229.     int            lshift;
  230.     int            widthGlyphs;
  231. #ifdef USE_LEFTBITS
  232.     register int        glyphMask;
  233.     register unsigned int   tmpSrc;
  234.     register int        glyphBytes;
  235. #endif
  236.  
  237.     pci = &pfi->maxbounds;
  238.     widthGlyph = pci->metrics.characterWidth;
  239.     h = pfi->fontAscent + pfi->fontDescent;
  240.     if (!h)
  241.     return;
  242.     x = xInit + pci->metrics.leftSideBearing + pDrawable->x;
  243.     y = yInit - pfi->fontAscent + pDrawable->y;
  244.     bbox.x1 = x;
  245.     bbox.x2 = x + (widthGlyph * nglyph);
  246.     bbox.y1 = y;
  247.     bbox.y2 = y + h;
  248.  
  249.     switch ((*pGC->pScreen->RectIn)(
  250.                 ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  251.     {
  252.       case rgnPART:
  253.     miImageGlyphBlt(pDrawable, pGC, xInit, yInit, nglyph, ppci, pglyphBase);
  254.       case rgnOUT:
  255.     return;
  256.     }
  257.  
  258.     if (!cfb8CheckPixels (pGC->fgPixel, pGC->bgPixel))
  259.     cfb8SetPixels (pGC->fgPixel, pGC->bgPixel);
  260.  
  261.     leftChar = 0;
  262.     if (pDrawable->type == DRAWABLE_WINDOW)
  263.     {
  264.     pdstBase = (unsigned long *)
  265.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  266.     widthDst = (int)
  267.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  268.     }
  269.     else
  270.     {
  271.     pdstBase = (unsigned long *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  272.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  273.     }
  274.     widthGlyphs = widthGlyph << 2;
  275.  
  276. #ifdef USE_LEFTBITS
  277.     glyphMask = endtab[widthGlyph];
  278.     glyphBytes = GLYPHWIDTHBYTESPADDED(pci);
  279. #endif
  280.  
  281.     pdstBase += y * widthDst;
  282.     if (nglyph >= 4 && widthGlyphs <= 32)
  283.     {
  284.     while (nglyph >= 4)
  285.     {
  286.         nglyph -= 4;
  287.         hTmp = h;
  288.         dstLine = pdstBase + (x >> 2);
  289.         xoff1 = x & 0x3;
  290.         xoff2 = xoff1 + widthGlyph;
  291.         xoff3 = xoff2 + widthGlyph;
  292.         xoff4 = xoff3 + widthGlyph;
  293.         char1 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  294.         char2 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  295.         char3 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  296.         char4 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  297.         oldRightChar = char4;
  298.         dst = dstLine;
  299.         if (xoff1)
  300.         {
  301.         ew = ((widthGlyphs - (4 - xoff1)) >> 2) + 1;
  302.             if (!leftChar)
  303.             {
  304.             leftMask = cfbendtab[xoff1];
  305.             rightMask = cfbstarttab[xoff1];
  306.  
  307. #define Step        NextFourBits(c);
  308. #define Loop        dst += widthDst;
  309. #define StoreBits0    dst[0] = dst[0] & leftMask | GetFourPixels(c) & rightMask;
  310.  
  311. #if (BITMAP_BIT_ORDER == MSBFirst)
  312. #define StoreBits(o)    dst[o] = GetFourPixels(c);
  313. #define FirstStep    Step
  314. #else
  315. #define StoreBits(o)    dst[o] = *((unsigned long *) (((char *) cfb8Pixels) + (c & 0x3c)));
  316. #define FirstStep    c = BitLeft (c, 2);
  317. #endif
  318.  
  319. #define GetBits GetBits4S
  320.  
  321.             SwitchEm
  322.  
  323. #undef GetBits
  324. #undef StoreBits0
  325.  
  326.             }
  327.             else
  328.             {
  329.             lshift = widthGlyph - xoff1;
  330.  
  331. #define StoreBits0  dst[0] = GetFourPixels(c);
  332.  
  333. #define GetBits GetBits4L
  334.  
  335.             SwitchEm
  336.  
  337. #undef GetBits
  338.  
  339.             }
  340.         }
  341.         else
  342.         {
  343.             ew = widthGlyph;    /* widthGlyphs >> 2 */
  344.  
  345. #define GetBits    GetBits4U
  346.  
  347.             SwitchEm
  348.  
  349. #undef GetBits
  350.  
  351.         }
  352.         x += widthGlyphs;
  353.         leftChar = oldRightChar;
  354.     }
  355.     }
  356.     while (nglyph--)
  357.     {
  358.     xoff1 = x & 0x3;
  359.     char1 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  360.     hTmp = h;
  361.     dstLine = pdstBase + (x >> 2);
  362.     oldRightChar = char1;
  363.     dst = dstLine;
  364.     if (xoff1)
  365.     {
  366.         ew = ((widthGlyph - (4 - xoff1)) >> 2) + 1;
  367.         if (!leftChar)
  368.         {
  369.         leftMask = cfbendtab[xoff1];
  370.         rightMask = cfbstarttab[xoff1];
  371. #undef StoreBits0
  372. #define StoreBits0    dst[0] = dst[0] & leftMask | GetFourPixels(c) & rightMask;
  373. #define GetBits    GetBits1S
  374.  
  375.         SwitchEm
  376. #undef GetBits
  377. #undef StoreBits0
  378.  
  379.         }
  380.         else
  381.         {
  382.         lshift = widthGlyph - xoff1;
  383. #define GetBits GetBits1L
  384.  
  385. #define StoreBits0  dst[0] = GetFourPixels(c);
  386.  
  387.         SwitchEm
  388. #undef GetBits
  389.         }
  390.     }
  391.     else
  392.     {
  393.         ew = widthGlyph >> 2;
  394. #define GetBits    GetBits1U
  395.  
  396.         SwitchEm
  397. #undef GetBits
  398.  
  399.     }
  400.     x += widthGlyph;
  401.     leftChar = oldRightChar;
  402.     }
  403.     /*
  404.      * draw the tail of the last character
  405.      */
  406.     xoff1 = x & 3;
  407.     if (xoff1)
  408.     {
  409.     rightMask = cfbstarttab[xoff1];
  410.     leftMask = cfbendtab[xoff1];
  411.     lshift = widthGlyph - xoff1;
  412.     dst = pdstBase + (x >> 2);
  413.     hTmp = h;
  414.     while (hTmp--)
  415.     {
  416.         GetBitsL
  417.         *dst = (*dst & rightMask) | (GetFourPixels(c) & leftMask);
  418.         dst += widthDst;
  419.     }
  420.     }
  421. }
  422. #endif /* PPW == 4 */
  423.